package com.mars.manager.web.controller;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.mars.common.utils.CookieUtils;
import com.mars.common.utils.HttpClientUtil;
import com.mars.manager.constant.Const;
import com.mars.manager.service.PassportService;
import com.mars.web.common.support.BaseController;

@Controller
@RequestMapping("/passport")
public class PassportController extends BaseController {
	
	@Autowired
	private PassportService passportService ;
	
	/**
	 * Cookie中Token的KEY 
	 */
	@Value("${SSO_COOKIE_TOKEN}")
	private String SSO_COOKIE_TOKEN ;
	
	/**
	 * 根据Token删除储存在Redis缓存中的用户信息服务
	 */
	@Value("${SSO_BOSS_DEL_REDIS_SESSION_USER_URL}")
	private String SSO_BOSS_DEL_REDIS_SESSION_USER_URL ;
	
	/**
	 * 登陆页面
	 */
	@Value("${SSO_BOSS_LOGIN_URL}")
	private String SSO_BOSS_LOGIN_URL ;
	
	/**
	 * 注销
	 */
	@RequestMapping(value="/logout", method=RequestMethod.GET)
	public String logout(HttpServletResponse response) {
		//删除局部Session当前用户信息
		this.request.getSession().removeAttribute(Const.CurrentUser); ;
		
		String token = CookieUtils.getCookieValue(request, SSO_COOKIE_TOKEN) ;
		if(null != token) {
			//删除Redis缓存中的RedisSession
			HttpClientUtil.doGet(SSO_BOSS_DEL_REDIS_SESSION_USER_URL + token) ;
		}
		//重定向到SSO登陆页面
		return "redirect:"+SSO_BOSS_LOGIN_URL;
	}
	
}
